Skip to content

feat(PostgreSQL): 增加数组类型字段支持#106

Merged
zhou-hao merged 5 commits into
4.2from
feat/postgresql-array-support
May 19, 2026
Merged

feat(PostgreSQL): 增加数组类型字段支持#106
zhou-hao merged 5 commits into
4.2from
feat/postgresql-array-support

Conversation

@zhou-hao
Copy link
Copy Markdown
Member

@zhou-hao zhou-hao commented May 19, 2026

目的

  • 为 easyorm PostgreSQL 方言增加一维数组类型的一等支持
  • 避免业务模块继续通过 columnDef("smallint[]") 等方式绕过 ORM 类型系统
  • 修复新版本 Docker Desktop / Testcontainers 环境下 PostgreSQL 集成测试无法执行的问题
  • 补齐 PostgreSQL 数组场景下的完整 Repository 集成测试覆盖

核心变动

  • 新增 PostgresqlArrayType,统一封装 PostgreSQL 数组类型的 DataTypeValueCodecDataTypeBuilder
  • PostgresqlDialect 中注册 varchar[]text[]smallint[]integer[]bigint[] 及 PG 内部别名 _varchar_text_int2_int4_int8
  • 新增 PostgreSQL 数组 typed binder:
    • JdbcParameterBinder
    • R2dbcParameterBinder
    • PostgresqlArrayParameter
  • 修复 JDBC / R2DBC 下数组条件参数绑定,确保 text[]smallint[] 等按正确 PostgreSQL 数组类型传参,避免 text[] = character varying[] 类型错误
  • 升级 org.testcontainers:testcontainers1.17.1 -> 1.21.4,兼容当前 Docker Desktop 环境
  • 修正 PostgreSQL 元数据测试中 json/jsonb 的断言,使其与 PostgreSQL 方言 JDBCType.OTHER 语义一致
  • 补充完整 Repository 集成测试,覆盖 sync/reactive 两套仓储 API 的 CRUD、save、批量插入、DSL update/delete、deleteById 等能力

测试结果

  • 环境:macOS + Docker Desktop 4.63.0 + Docker Engine 29.2.1 + JDK 17
  • 编译验证:
    • mvn -pl hsweb-easy-orm-rdb -am -DskipTests compile
    • mvn -pl hsweb-easy-orm-rdb -am -DskipTests test-compile
  • PostgreSQL 数组相关测试:
    • mvn -pl hsweb-easy-orm-rdb -am -Dsurefire.failIfNoSpecifiedTests=false -Dtest=PostgresqlArraySupportTest,PostgresqlTableMetaParserTest,org.hswebframework.ezorm.rdb.supports.postgres.array.PostgresqlArrayTest test
    • 结果:Tests run 9, Failures 0, Errors 0, Skipped 0, BUILD SUCCESS
  • 完整 Repository 集成测试:
    • mvn -pl hsweb-easy-orm-rdb -am -Dsurefire.failIfNoSpecifiedTests=false -Dtest=org.hswebframework.ezorm.rdb.supports.postgres.array.PostgresqlArrayTest test
    • 结果:Tests run 4, Failures 0, Errors 0, Skipped 0, BUILD SUCCESS

验证场景

  • 数组 codec:Collection / Java 数组 / PG 字面量 / PGobject
  • 表结构解析:
    • varchar[]
    • text[]
    • smallint[]
    • integer[]
    • bigint[]
  • Repository round-trip:
    • JDBC 插入 / 查询
    • R2DBC 插入 / 查询
  • 数组等值过滤:
    • smallint[]
    • text[]
  • 完整仓储能力:
    • save
    • insertBatch
    • updateById
    • findById
    • createQuery
    • createUpdate
    • createDelete
    • deleteById

文档同步情况

  • 当前 PR 无需同步额外文档

风险与说明

  • 本次对执行器层新增了很小的 typed parameter binder 扩展点,用于支持 PostgreSQL 数组等需要显式类型绑定的场景
  • 该扩展点未侵入现有普通参数路径,默认行为保持不变

增量更新(2026-05-19)

  • 新增通用数组相关 termType:containsncontainscontainedncontainedoverlapnoverlap
  • 在 core DSL 中补充:contains/notContainscontained/notContainedoverlap/notOverlap
  • PostgreSQL 数组列条件映射:
    • contains -> @>
    • contained -> <@
    • overlap -> &&
    • 数组列 in 兼容为 overlap(任一命中)
    • 数组列 in$all 兼容为 contains(全部命中)
  • 升级 org.jacoco:jacoco-maven-plugin0.8.8 -> 0.8.14,兼容 JDK 21,消除 Unsupported class file major version 65 instrumentation 警告

增量测试结果(2026-05-19)

  • 环境:macOS + Docker Desktop 4.63.0 + Docker Engine 29.2.1 + JDK 21
  • sh mvnw -pl hsweb-easy-orm-core -Dtest=QueryTest test
    • 结果:Tests run 2, Failures 0, Errors 0, Skipped 0, BUILD SUCCESS
  • sh mvnw -pl hsweb-easy-orm-rdb -am -Dtest=PostgresqlArrayTest -Dsurefire.failIfNoSpecifiedTests=false test
    • 结果:Tests run 6, Failures 0, Errors 0, Skipped 0, BUILD SUCCESS
  • JaCoCo 升级后,验证日志中不再出现 Unsupported class file major version 65 告警

增量修复(2026-05-19 / R2DBC 兼容)

  • 修复 PostgresqlArrayType 对 JDBC org.postgresql.util.PGobject 的硬依赖
  • 调整为按类名判断并通过反射读取 getValue(),避免纯 R2DBC / 无 JDBC driver 场景下触发 ClassNotFoundException
  • 该修复对 retrieval-pg 这类仅使用 PostgreSQL R2DBC 驱动但复用 easyorm PostgreSQL 数组 term / codec 的模块是必需的

补充验证

  • sh mvnw -pl hsweb-easy-orm-rdb -am -Dtest=PostgresqlArrayTest -Dsurefire.failIfNoSpecifiedTests=false test
    • 结果:Tests run 6, Failures 0, Errors 0, Skipped 0, BUILD SUCCESS

@zhou-hao zhou-hao marked this pull request as ready for review May 19, 2026 03:57
@zhou-hao
Copy link
Copy Markdown
Member Author

已补充修复本次 Actions 失败点,PR head 已更新到 305d875197ff1982aa148c7832b33805f1ce440b

本次修复:

  • 修复 BatchInsertSqlBuilder 在 upsert 仅传非主键列时的主键去重越界
  • 修复 PostgreSQL/OpenGauss 批量保存 LONGNVARCHAR/JSON 空值时 JDBC setNull 类型不兼容问题
  • BasicCommonTests.testRepositoryBatchSave 改为稳定断言,移除会连到新 H2 内存库的调试 SQL
  • 加强 PostgreSQL Testcontainers 等待条件,并移除 provider 中重复覆盖等待策略

已本地验证通过:

  • DefaultSaveOrUpdateOperatorTest
  • H2BasicTest#testRepositoryBatchSave
  • PostgresqlBasicTest#testRepositoryBatchSave
  • OpengaussBasicTest#testRepositoryBatchSave
  • Postgresql12ReactiveTests#testException
  • mvn -pl hsweb-easy-orm-rdb -am 的大部分回归已跑过并通过,当前完整 mvn test 仍在本地继续执行(主要耗时在首次拉取大镜像)

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 19, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 64.20664% with 97 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.63%. Comparing base (68b2764) to head (baa35cc).
⚠️ Report is 39 commits behind head on 4.2.

Files with missing lines Patch % Lines
...orm/rdb/supports/postgres/PostgresqlArrayType.java 66.17% 27 Missing and 19 partials ⚠️
...db/supports/postgres/PostgresqlArrayParameter.java 34.78% 10 Missing and 5 partials ⚠️
...org/hswebframework/ezorm/core/NestConditional.java 0.00% 12 Missing ⚠️
...s/postgres/PostgresqlArrayTermFragmentBuilder.java 75.00% 5 Missing and 7 partials ⚠️
...ava/org/hswebframework/ezorm/core/Conditional.java 50.00% 6 Missing ⚠️
...uilder/fragments/insert/BatchInsertSqlBuilder.java 33.33% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                4.2     #106      +/-   ##
============================================
+ Coverage     64.92%   65.63%   +0.70%     
- Complexity     2341     2390      +49     
============================================
  Files           343      357      +14     
  Lines          9375     9977     +602     
  Branches        940     1123     +183     
============================================
+ Hits           6087     6548     +461     
- Misses         2810     2867      +57     
- Partials        478      562      +84     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zhou-hao zhou-hao merged commit e7547d6 into 4.2 May 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants